@@ -10,8 +10,9 @@ class Scenario < ActiveRecord::Base |
||
| 10 | 10 |
validates_presence_of :name, :user |
| 11 | 11 |
|
| 12 | 12 |
validates_format_of :tag_fg_color, :tag_bg_color, |
| 13 |
- :with => /\A#(?:[0-9a-fA-F]{3}){1,2}\z/, :message => "must be a valid hex color."
|
|
| 14 | 13 |
# Regex adapted from: http://stackoverflow.com/a/1636354/3130625 |
| 14 |
+ :with => /\A#(?:[0-9a-fA-F]{3}){1,2}\z/, :allow_nil => true,
|
|
| 15 |
+ :message => "must be a valid hex color." |
|
| 15 | 16 |
|
| 16 | 17 |
validate :agents_are_owned |
| 17 | 18 |
|
@@ -1,6 +1,6 @@ |
||
| 1 | 1 |
class AddTagColorToScenarios < ActiveRecord::Migration |
| 2 | 2 |
def change |
| 3 |
- add_column :scenarios, :tag_bg_color, :string, default: '#5bc0de' |
|
| 4 |
- add_column :scenarios, :tag_fg_color, :string, default: '#ffffff' |
|
| 3 |
+ add_column :scenarios, :tag_bg_color, :string |
|
| 4 |
+ add_column :scenarios, :tag_fg_color, :string |
|
| 5 | 5 |
end |
| 6 | 6 |
end |
@@ -11,7 +11,7 @@ |
||
| 11 | 11 |
# |
| 12 | 12 |
# It's strongly recommended that you check this file into your version control system. |
| 13 | 13 |
|
| 14 |
-ActiveRecord::Schema.define(version: 20140605032822) do |
|
| 14 |
+ActiveRecord::Schema.define(version: 20140820003139) do |
|
| 15 | 15 |
|
| 16 | 16 |
create_table "agent_logs", force: true do |t| |
| 17 | 17 |
t.integer "agent_id", null: false |
@@ -111,8 +111,8 @@ ActiveRecord::Schema.define(version: 20140605032822) do |
||
| 111 | 111 |
t.boolean "public", default: false, null: false |
| 112 | 112 |
t.string "guid", null: false |
| 113 | 113 |
t.string "source_url" |
| 114 |
- t.string "tag_bg_color", default: "#5bc0de" |
|
| 115 |
- t.string "tag_fg_color", default: "#ffffff" |
|
| 114 |
+ t.string "tag_bg_color" |
|
| 115 |
+ t.string "tag_fg_color" |
|
| 116 | 116 |
end |
| 117 | 117 |
|
| 118 | 118 |
add_index "scenarios", ["user_id", "guid"], name: "index_scenarios_on_user_id_and_guid", unique: true, using: :btree |
@@ -5,15 +5,6 @@ describe Scenario do |
||
| 5 | 5 |
|
| 6 | 6 |
it_behaves_like HasGuid |
| 7 | 7 |
|
| 8 |
- describe "defaults" do |
|
| 9 |
- it "defaults the tag foreground color" do |
|
| 10 |
- new_instance.tag_fg_color.should == '#ffffff' |
|
| 11 |
- end |
|
| 12 |
- it "defaults the tag background color" do |
|
| 13 |
- new_instance.tag_bg_color.should == '#5bc0de' |
|
| 14 |
- end |
|
| 15 |
- end |
|
| 16 |
- |
|
| 17 | 8 |
describe "validations" do |
| 18 | 9 |
before do |
| 19 | 10 |
new_instance.should be_valid |
@@ -34,11 +25,21 @@ describe Scenario do |
||
| 34 | 25 |
new_instance.should_not be_valid |
| 35 | 26 |
end |
| 36 | 27 |
|
| 28 |
+ it "allows nil tag_fg_color" do |
|
| 29 |
+ new_instance.tag_fg_color = nil |
|
| 30 |
+ new_instance.should be_valid |
|
| 31 |
+ end |
|
| 32 |
+ |
|
| 37 | 33 |
it "validates tag_bg_color is hex color" do |
| 38 | 34 |
new_instance.tag_bg_color = '#N07H3X' |
| 39 | 35 |
new_instance.should_not be_valid |
| 40 | 36 |
end |
| 41 | 37 |
|
| 38 |
+ it "allows nil tag_bg_color" do |
|
| 39 |
+ new_instance.tag_bg_color = nil |
|
| 40 |
+ new_instance.should be_valid |
|
| 41 |
+ end |
|
| 42 |
+ |
|
| 42 | 43 |
it "only allows Agents owned by user" do |
| 43 | 44 |
new_instance.agent_ids = [agents(:bob_website_agent).id] |
| 44 | 45 |
new_instance.should be_valid |